package cn.tedu.tmall.admin.mall.dao.repository.impl;

import cn.tedu.tmall.admin.mall.dao.mapper.MallCategoryMapper;
import cn.tedu.tmall.admin.mall.dao.repository.IMallCategoryRepository;
import cn.tedu.tmall.admin.mall.pojo.po.MallCategoryPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class MallCategoryRepository implements IMallCategoryRepository {
    @Autowired
    private MallCategoryMapper categoryMapper;
    @Override
    public Long countCategoryByName(String name) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("name",name);
        return categoryMapper.selectCount(queryWrapper);
    }

    @Override
    public void save(MallCategoryPO categoryPO) {
        categoryMapper.insert(categoryPO);
    }

    @Override
    public MallCategoryPO getCategoryById(Long id) {
        return categoryMapper.selectById(id);
    }

    @Override
    public void updateCategoryById(MallCategoryPO update) {
        categoryMapper.updateById(update);
    }

    @Override
    public List<MallCategoryPO> listCategoryByPrentId(Long parentId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("parent_id",parentId);
        return  categoryMapper.selectList(queryWrapper);
    }

    @Override
    public List<MallCategoryPO> getAll() {
            QueryWrapper queryWrapper = new QueryWrapper();
        return categoryMapper.selectList(queryWrapper);
    }
}
